home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: ifstream slower than fread()?
- Date: 13 Jan 1996 04:10:53 GMT
- Organization: Pipeline USA
- Message-ID: <4d7bcd$4l6@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 12, 1996 20:00:31 in article <ifstream slower than fread()?>,
- 'jritzau@aol.com (JRitzau)' wrote:
-
-
- >Hello!
- >
- >I was thinking iostreams of C++ are the best way to read
- >and write binary files. But after testing I must see, that
- >to copy a file with 'old' C-functions fwrite()/fread() do
- >the job in just about half the time it was done using
- >ifstream.read()/ofstream.write()?!
- >
- The iostream vs stdio speed issue was just discussed in the
- last couple of days. Read the last three days' posts for more
- info. Also, the FAQ (questions circa 100) deal with this topic.
-
- IMO, this speed difference is mostly due to your old compiler
- system. C stdio has been around a long time and has been
- optimized while at the time BC3.0 was developed, iostreams
- were still in their infancy.
-
- I don't see a whole lot of apparent speed difference between
- the two, but then again, I typically don't use iostreams
- for binary files. I'd copy the file by getting its size, allocate
- a buffer, and do one each fread()/fwrite(). Now, that's fast.
- (Don't ask -- I've provided for files too big for this treatment).
-
- >Next problem: I've read that I must call the function
- >ios::sync_with_stdio() if one program uses printf() AND cout.
- >
- Only if you want the text to appear at the output device in the
- same sequence as your code's output.
-
- >Is there also a need for this synchronisation if I use
- >fread()/fwrite() (no printf()) AND cin/cout in the same
- >program?
-
- No. (Just don't redirect cin or cout to the same file you
- are are doing fread/fwrite. :-))
-
- --
-
- Pete
-